﻿using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using ChBusiness.User;

/// <summary>
/// 用于登录的接口--可删除
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class LoginInterface : System.Web.Services.WebService
{

    public LoginInterface()
    {
        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }
    /// <summary>
    /// 用户统一登陆接口，同一个客户端三次登陆失败时直接拒绝
    /// </summary>
    /// <param name="userId"></param>
    /// <param name="pwd"></param>
    /// <returns></returns>
    [WebMethod(EnableSession=true)]
    public bool  Login(string sysType, string userId,string pwd)
    {
        if (true == UserHandle.CheckUserExist(userId,sysType)
            &&UserHandle.UserIsvalid(userId)
            &&UserHandle.CheckPassword(userId, pwd))
        {

            //获取用户所属行政区
            if (ChBusiness.SystemConfig.IsInternet == 1)
            {
                if (Session["UserSectionId"] == null)
                {
                    Session["UserSectionId"] = ChBusiness.User.UserHandle.GetSectionId(userId);
                }
            }
            Session["UserID"] = userId;

            return true;
        }
        else//验证失败时检测此用户失败了几次了，如果超过三次，直接返回。
        {
            if (Session["LoginInterNumber"] == null)
            {
                Session["LoginInterNumber"] = 1;
            }
            else
            {
                int num=int.Parse(Session["LoginInterNumber"].ToString());
                if (num > 3) return false;
                else
                    Session["LoginInterNumber"] = num + 1;
            }
            return false;
        }
    }
}

